const { createProxyMiddleware } = require('http-proxy-middleware');

// 
module.exports = function (app) {
    //设置代理
    app.use(
        '/api1',  // 路径的前缀
        createProxyMiddleware({
            target: 'http://localhost:5000',
            changeOrigin: true,   //固定写法, 用来伪装 host 请求头, 提高跨域请求成功率
            pathRewrite: {'^/api1': ''} //调整路径 路径重写   /api1/students   =>  /students
        }),
    );

    app.use(
        '/api2',  // 路径的前缀
        createProxyMiddleware({
            target: 'http://localhost:5001',
            changeOrigin: true,   //固定写法, 用来伪装 host 请求头, 提高跨域请求成功率
            pathRewrite: {'^/api2': ''}
        }),
    );

    app.use(
        '/zhihu',  // 路径的前缀
        createProxyMiddleware({
            target: 'https://www.zhihu.com',
            changeOrigin: true,   //固定写法, 用来伪装 host 请求头, 提高跨域请求成功率
            pathRewrite: {'^/zhihu': ''}
        }),
    );
};